//
//  RHMySuperUserInfoVC.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/10/29.
//

#import "RHMySuperUserInfoVC.h"
#import "RHUserModel.h"
#import "RHTools.h"

@interface RHMySuperUserInfoVC ()

@end

@implementation RHMySuperUserInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = CFTabViewBgColor;
    self.navigationItem.title = @"我的上级用户".rh_localized;
    [self setupUI];
}

-(void)setupUI
{
    RHUserModel *userModel = [PrivateMange share].currentUser;
    UIView *topView = kView;
    topView.layer.cornerRadius = 8;
    topView.layer.masksToBounds = YES;
    topView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_offset(15);
        make.right.mas_offset(-15);
    }];
    
    UIView *userNameView = [self itemViewWithTitle:@"用户名称".rh_localized content:userModel.superUsername showLine:NO];
    [topView addSubview:userNameView];
    [userNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.mas_offset(0);
        make.bottom.mas_offset(0);
    }];
    
    
    
    
    UIView *botView = kView;
    botView.layer.cornerRadius = 8;
    botView.layer.masksToBounds = YES;
    botView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:botView];
    [botView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom).offset(15);
        make.left.right.equalTo(topView);
    }];
    
    
//    NSString *roleStr = [RHTools getRoleContentWithType:userModel.superHierarchyCode];
    NSString *roleStr = @"";
    UIView *roleView = [self itemViewWithTitle:@"用户角色".rh_localized content:roleStr showLine:YES];
    [botView addSubview:roleView];
    [roleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.mas_offset(0);
    }];
    
    
    UIView *emailView = [self itemViewWithTitle:@"用户邮箱".rh_localized content:userModel.superAdminEmail showLine:YES];
    [botView addSubview:emailView];
    [emailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(roleView.mas_bottom);
    
    }];
    
    UIView *contactView = [self itemViewWithTitle:@"联系方式".rh_localized content:userModel.superPhonenumber showLine:YES];
    [botView addSubview:contactView];
    [contactView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(emailView.mas_bottom);

    }];
    
    UIView *adressView = [self itemViewWithTitle:@"用户地址".rh_localized content:userModel.superAdminAddress showLine:NO];
    [botView addSubview:adressView];
    [adressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(contactView.mas_bottom);
        make.bottom.mas_offset(0);
    }];
    
    
}

-(UIView*)itemViewWithTitle:(NSString*)title content:(NSString *)content showLine:(BOOL)showLine
{
    UIView *bgView = kView;
    QMUILabel *titleLab = [QMUILabel labelWithText:title font:kSYSTEMFONT(14) textColor:kCOLOR_HEX_A(@"#171A1D", 0.8)];
    titleLab.textAlignment = NSTextAlignmentLeft;
    titleLab.numberOfLines = 2;
    titleLab.adjustsFontSizeToFitWidth = YES;
    titleLab.minimumScaleFactor = 0.8;
    [bgView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(0);
        make.top.mas_offset(10);
        make.bottom.mas_offset(-10);
        make.width.offset(100);
        make.height.greaterThanOrEqualTo(@(25));
    }];
    
    QMUILabel *textField = [[QMUILabel alloc]init];
    textField.textColor = kCOLOR_HEX(@"#171A1D");
    textField.font = kSYSTEMFONT(14);
    textField.text = content;
    textField.numberOfLines = 0;
    [bgView addSubview:textField];
    
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_right).offset(5);
        make.right.mas_offset(-0);
        make.top.mas_offset(10);
        make.bottom.mas_offset(-10);
        make.height.greaterThanOrEqualTo(@(25));
    }];
    if (showLine) {
        UIView *line = kView;
        line.backgroundColor = kCOLOR_HEX(@"#EBEDF0");
        [bgView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titleLab);
            make.bottom.mas_offset(0);
            make.right.equalTo(textField);
            make.height.offset(1);
        }];
    }

    return bgView;
}




@end
